<template>
    <div class="content-container" v-loading="loading">
        <!-- 数据服务器设置 -->
        <div class="form-box">
            <div
                v-for="(item, index) in settingInfo.server_info"
                :key="index"
            >
                <div class="form-title">
                    <span class="title-text">
                        {{index === 0 ? '业务模式-数据服务器设置' : '科研模式-数据服务器设置'}}
                        <i class="el-icon-info" @click="serverConnectBefor(index, true)"></i>
                    </span>
                    <el-select v-model="item.server_name" placeholder="服务器类型" size="mini" style="width: 100px">
                        <el-option value="ssh" label="SSH"></el-option>
                        <el-option value="ftp" label="FTP"></el-option>
                        <el-option value="sftp" label="SFTP"></el-option>
                    </el-select>
                    <el-switch
                        v-model="item.is_load"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-text="缓存数据"
                        inactive-text="不缓存数据"
                        @change="change_server_load(index, item.is_load)"
                        :active-value="1"
                        :inactive-value="0"
                    ></el-switch>
                </div>
                <el-form 
                    :model="item"
                    :rules="serverformRules"
                    label-width="100px"
                    label-position="top"
                    ref="server_info"
                    hide-required-asterisk
                    v-if="!loading"
                >
                    <el-row :gutter="40">
                        <el-col :span="8">
                            <el-form-item label="服务器地址" prop="url">
                                <el-input v-model="item.url" placeholder="请输入服务器地址"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="用户名" prop="name">
                                <el-input v-model="item.name" placeholder="请输入用户名"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="密码" prop="pwd">
                                <el-input v-model="item.pwd" placeholder="请输入密码" show-password></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="path === 'global_deterministic'">
                            <el-form-item label="全球确定性预报检验数据存放路径" prop="data_path">
                                <el-input v-model="item.data_path" placeholder="请输入数据存放路径"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="path === 'grapes_region_determ'">
                            <el-form-item label="区域确定性模式-等压面要素预报数据-存放路径" prop="obs_data_path">
                                <el-input v-model="item.obs_data_path" placeholder="请输入数据存放路径"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="path === 'grapes_region_determ'">
                            <el-form-item label="等压面要素观测数据-存放路径" prop="fcst_data_path">
                                <el-input v-model="item.fcst_data_path" placeholder="请输入数据存放路径"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="path === 'grapes_reps' && index !== 1">
                            <el-form-item label="中国区域站点累计降水观测数据-存放路径" prop="obs_data_path">
                                <el-input v-model="item.obs_data_path" placeholder="请输入数据存放路径"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="path === 'grapes_reps'">
                            <el-form-item label="GRAPES区域模式预报数据-存放路径" prop="fcst_data_path">
                                <el-input v-model="item.fcst_data_path" placeholder="请输入数据存放路径"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div class="server-connect-test">
                        <el-button type="primary" round style="font-size: 14px" @click="serverConnectBefor(index, false)">
                            <i class="el-icon-refresh"></i>
                            <span>服务器连接测试</span>
                        </el-button>
                    </div>
                </el-form>
            </div>

            <el-dialog title="服务器连接测试前确认" :visible.sync="server_connect_info" width="700px">
            <p v-if="path === 'global_deterministic' || path === 'grapes_region_determ'">
                请确认<b>“全球确定性预报形势场检验数据-存放路径”</b>中输入的是数据根路径，并保证完整数据路径符合以下规范：<br>
                数据完整路径格式规范：<b>数据根路径</b>/模式名/stats.日期<br>
                示例：<br>
                数据完整路径为：/g1/u/user/vsdb_data/plev/ECMWF/stats.2019010100<br>
                则输入的根路径为：<b>/g1/u/user/vsdb_data/plev</b>
            </p>
            <p v-if="path === 'grapes_reps' && server_connect_index !== 1">
                请确认<b>“中国区域站点累计降水观测数据-存放路径”</b>中输入的是站点累计降水观测数据根路径，并保证完整数据路径符合以下规范：<br>
                数据完整路径格式规范：<b>站点累计降水观测数据根路径</b>/rain_累计时长/年月/rain累计时长_日期.dat<br>
                (注：累计24小时的观测数据路径比较特殊，其规范为：<b>站点累计降水观测数据根路径</b>/rain_24/rain_08/rain_0400sta/rain24_日期.dat)<br>
                示例1：<br>
                数据完整路径为：/g1/u/user/grapes-reps/obs/rain/rain_01/201912/rain01_1912010.dat <br>
                则输入的根路径为：<b>/g1/u/user/grapes-reps/obs/rain</b><br>
                示例2：<br>
                数据完整路径为：/g1/u/user/grapes-reps/obs/rain/rain_24/rain_08/rain_0400sta/rain01_1912010.dat <br>
                则输入的根路径为：<b>g1/u/user/grapes-reps/obs/rain/</b><br>
            </p>
            <p v-if="path === 'grapes_reps'">
                请确认<b>“GRAPES区域模式预报数据-存放路径”</b>中输入的是区域预报数据根路径，并保证完整数据路径符合以下规范：<br>
                数据完整路径格式规范：<b>区域预报数据根路径</b>/年月日/sfc-年月日时.grib2 <br>
                示例：<br>
                数据完整路径为：/g1/u/user/grapes-reps/mesofcst/2021030112/sfc-2021030112000.grib2 <br>
                则输入的根路径为：<b>/g1/u/user/grapes-reps/mesofcst</b><br>
                <b>注意：</b>每个grib2文件必须包含15个成员的降雨预报数据，地理范围必须涵盖中国区域，否则计算程序会运行出错！<br>
            </p>
            <span slot="footer" class="dialog-footer">
                <div v-if="!server_connect_isInfo">
                    <el-button @click="server_connect_info = false">取 消</el-button>
                    <el-button type="primary" @click="serverConnetTest('server_info', server_connect_index)">确认测试连接</el-button>
                </div>
            </span>
        </el-dialog>
        </div>

        <!-- 显著性检验设置 -->
        <div class="form-box">
            <div class="form-title">
                <span class="title-text">{{path != 'grapes_reps'?'显著性检验设置':'集合预报成员数缺失阈值设置'}}</span>
            </div>
            <el-form
                label-width="110px"
                inline
                label-position="left"
                :model="settingInfo"
                :rules="significanceformRules"
                hide-required-asterisk
                ref="significanceForm"
                v-if="!loading"
            >
                <el-form-item v-if="path == 'global_deterministic' || path === 'grapes_region_determ'" label="样本数阈值" prop="thresholds">
                    <el-input-number
                        v-model.number="settingInfo.thresholds"
                        :min="2"
                        @change="changeThresholds"
                    ></el-input-number>
                </el-form-item>
                <el-form-item v-if="path == 'grapes_reps'" label="缺失成员数阈值" prop="thresholds">
                    <el-input-number
                        v-model.number="settingInfo.thresholds"
                        :min="0"
                        :max="14"
                        @change="changeThresholds"
                    ></el-input-number>
                </el-form-item>
                <el-row v-if="path == 'global_deterministic' || path === 'grapes_region_determ'">
                    <el-col :span="8">
                        <el-form-item label="置信度a" prop="confidence_a">
                            <el-input type="number" v-model.number="settingInfo.confidence_a" @change="changeConfidence(1, settingInfo.confidence_a)"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="置信度b" prop="confidence_b">
                            <el-input type="number" v-model.number="settingInfo.confidence_b" @change="changeConfidence(2, settingInfo.confidence_b)"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="置信度c" prop="confidence_c">
                            <el-input type="number" v-model.number="settingInfo.confidence_c" @change="changeConfidence(3, settingInfo.confidence_c)"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>

        <!-- 检验数据相关设置 -->
        <div class="form-box">
            <div class="form-title">
                <span class="title-text">检验数据相关设置</span>
            </div>
            <el-form label-position="left">
                <el-form-item>
                    <el-button plain class="function-button" @click="getCacheData">查看当前项目模块缓存数据</el-button>
                    <el-button plain class="function-button" @click="delcacheData">清空当前项目模块缓存数据</el-button>
                </el-form-item>
            </el-form>
            
            <!-- 当前模块缓存数据弹窗 -->
            <el-dialog title="当前项目模块缓存数据" :visible.sync="cacheDialog" :width="'600px'">
                <el-table
                    :data="cacheData"
                    :header-cell-style="{backgroundColor: '#F3F3F3'}"
                    max-height="400px"
                    height="400px"
                    v-loading="dialogLoading"
                    :span-method="path == 'grapes_region_determ'?cacheSpanMethod:null"
                    border
                    cell-class-name="cache-table-cell"
                >
                    <el-table-column property="type" label="数据类型" v-if="path == 'grapes_region_determ'"></el-table-column>
                    <el-table-column property="mode" label="模式" width="150"></el-table-column>
                    <el-table-column property="date" label="日期"></el-table-column>
                    <el-table-column property="element" label="气象要素" width="180" v-if="path == 'grapes_reps'"></el-table-column>
                    <el-table-column property="skillscores" label="技巧评分" v-if="path == 'grapes_reps'"></el-table-column>
                </el-table>
            </el-dialog>
        </div>
        
        <!-- 项目模块管理相关设置 -->
        <div class="form-box">
            <div class="form-title">
                <span class="title-text">项目模块管理相关设置</span>
            </div>
            <el-form>
                <el-form-item>
                    <el-button plain class="function-button" @click="getmemberData">当前项目人员管理</el-button>
                    <el-button plain class="function-button" @click="getorderData(1)">项目运行日志查看</el-button>
                </el-form-item>
            </el-form>

            <!-- 当前项目人员对话框 -->
            <el-dialog :title="'当前项目人员管理'" :visible.sync="memberDialog" width="400px">
                <el-table
                    :data="memberData"
                    :header-cell-style="{backgroundColor: '#F3F3F3'}"
                    border
                    v-loading="dialogLoading"
                    max-height="400px"
                    height="400px"
                >
                    <el-table-column type="index" width="50"></el-table-column>
                    <el-table-column prop="name" label="姓名"></el-table-column>
                    <el-table-column prop="position" label="权限"></el-table-column>
                    <el-table-column label="操作" width="50">
                        <template slot-scope="scope">
                            <el-button icon="el-icon-delete" type="text" style="color: #666666;" @click="delmember(scope.row)"></el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-button
                    icon="el-icon-circle-plus-outline"
                    type="text"
                    style="color: #409EFF;font-size: 14px;"
                    @click="addmemberDialog = true"
                >添加新成员</el-button>
                
                <!-- 添加新成员对话框 -->
                <el-dialog top="25vh" title="人员搜索" :visible.sync="addmemberDialog" width="350px" :modal="false">
                    <el-select
                        v-model="searchMemberId"
                        placeholder="请输入要搜索的用户名"
                        filterable
                        remote
                        :remote-method="searchMember"
                        :loading="searchLoading"
                        clearable
                    >
                        <el-option
                            v-for="item in searchResult"
                            :key="item.id"
                            :value="item.id"
                            :label="item.name"
                        >
                            <span style="float: left">{{ item.name }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">ID：{{ item.id }}</span>
                        </el-option>
                    </el-select>

                    <span slot="footer" class="dialog-footer" v-show="searchMemberId!==''">
                        <el-button @click="addmemberDialog = false">取 消</el-button>
                        <el-button type="primary" @click="addMember(searchMemberId)">确 定</el-button>
                    </span>
                </el-dialog>
            </el-dialog>

            <!-- 项目运行日志对话框 -->
            <el-dialog title="项目运行日志" :visible.sync="runlogDialog" :width="'700px'">
                <div style="display: flex;flex-direction: column;align-items: center;">
                    <el-table
                        :data="runlogData"
                        :header-cell-style="{backgroundColor: '#F3F3F3'}"
                        v-loading="dialogLoading"
                        style="flex-basis: auto"
                    >
                        <el-table-column property="marker" label="Marker">
                            <template slot-scope="scope">
                                <span style="color: #67C23A" v-if="scope.row.marker.indexOf('INFO') !== -1">{{scope.row.marker}}</span>
                                <span style="color: #F56C6C" v-if="scope.row.marker.indexOf('ERROR') !== -1">{{scope.row.marker}}</span>
                                <span style="color: #E6A23C" v-if="scope.row.marker.indexOf('WARN') !== -1">{{scope.row.marker}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column property="info" label="Info"></el-table-column>
                        <el-table-column property="time" label="Time"></el-table-column>
                    </el-table>
                    <el-pagination
                        small
                        layout="prev, pager, next"
                        :page-count="pagination.pageCount"
                        :current-page.sync="pagination.currentPage"
                        hide-on-single-page
                        @current-change="getorderData(pagination.currentPage)"
                    ></el-pagination>
                </div>
            </el-dialog>
        </div>

        <div class="form-box" v-if="path == 'ADdashboard'">
            <div class="form-title">
                <span class="title-text">坐标设置</span>
            </div>
            <el-form v-model="coordinate" label-width="150px" inline label-position="left">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="中心点坐标">
                            <el-input type="number" v-model="coordinate.center" class="coordinate-input">
                                <el-select v-model="coordinate.center_sign" size="mini" slot="append">
                                    <el-option
                                        v-for="item in ['N', 'S', 'E', 'W']"
                                        :key="item"
                                        :value="item">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="参考纬度1">
                            <el-input type="number" v-model="coordinate.first" class="coordinate-input">
                                <el-select v-model="coordinate.first_sign" size="mini" slot="append">
                                    <el-option
                                        v-for="item in ['N', 'S', 'E', 'W']"
                                        :key="item"
                                        :value="item">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="参考纬度2">
                            <el-input type="number" v-model="coordinate.second" class="coordinate-input">
                                <el-select v-model="coordinate.second_sign" size="mini" slot="append">
                                    <el-option
                                        v-for="item in ['N', 'S', 'E', 'W']"
                                        :key="item"
                                        :value="item">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="中心点相对X轴的距离">
                            <el-input type="number" v-model="coordinate.Xdistance" class="coordinate-input">
                                <span slot="suffix">KM</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="中心点相对Y轴的距离">
                            <el-input type="number" v-model="coordinate.Ydistance" class="coordinate-input">
                                <span slot="suffix">KM</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="开始网格宽度">
                            <el-input type="number" v-model="coordinate.startwidth" class="coordinate-input">
                                <span slot="suffix">KM</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>

        <div class="form-box" v-if="path == 'ADdashboard'">
            <div class="form-title">
                <span class="title-text">文件位置配置</span>
            </div>
            
            <el-form :model="configuration_path" label-position="left" label-width="250px">
                <el-row :gutter="20">
                    <el-col :span="24" :xl="12">
                        <el-form-item label="TERRER_DAT保存位置">
                            <el-input v-model="configuration_path.TERRER_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="TERRER_LST保存位置">
                            <el-input v-model="configuration_path.TERRER_LST" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CTGPROC_DAT保存位置">
                            <el-input v-model="configuration_path.CTGPROC_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CTGPROC_LST保存位置">
                            <el-input v-model="configuration_path.CTGPROC_LST" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="GLAZAS文件位置">
                            <el-input v-model="configuration_path.GLAZAS" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="MAKEGEO_LU_DAT文件位置">
                            <el-input v-model="configuration_path.MAKEGEO_LU_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="MAKEGEO_TERR_DAT文件位置">
                            <el-input v-model="configuration_path.MAKEGEO_TERR_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="GEO_DAT文件保存位置">
                            <el-input v-model="configuration_path.GEO_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="GRAPES文件目录">
                            <el-input v-model="configuration_path.GRAPES" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="GRAPES_23DDAT输出文件保存位置">
                            <el-input v-model="configuration_path.GRAPES_23DDAT_OUTPUT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="GRAPES_23DDAT配置文件位置">
                            <el-input v-model="configuration_path.GRAPES_23DDAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CALMET_GEO_DAT文件位置">
                            <el-input v-model="configuration_path.CALMET_GEO_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CALMET_LST文件保存位置">
                            <el-input v-model="configuration_path.CALMET_LST" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CALMET_DAT文件保存位置">
                            <el-input v-model="configuration_path.CALMET_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="M3DDAT文件位置">
                            <el-input v-model="configuration_path.M3DDAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="CALPUFF污染信息设置" label-width="180px"></el-form-item>

                        <el-form v-model="configuration_path.CALPUFF" label-width="100px" label-position="left">
                            <el-row style="margin-left: 30px" :gutter="20">
                                <el-col :span="12" :lg="7">
                                    <el-form-item label="坐标X">
                                        <el-input v-model="configuration_path.CALPUFF.x" class="CALPUFF-input">
                                            <span slot="suffix"></span>
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12" :lg="7">
                                    <el-form-item label="坐标Y">
                                        <el-input v-model="configuration_path.CALPUFF.y" class="CALPUFF-input">
                                            <span slot="suffix"></span>
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row style="margin-left: 30px" :gutter="20">
                                <el-col :span="12" :lg="7">
                                    <el-form-item label="烟囱高度">
                                        <el-input v-model="configuration_path.CALPUFF.height" class="CALPUFF-input">
                                            <span slot="suffix">M</span>
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12" :lg="7">
                                    <el-form-item label="烟气温度">
                                        <el-input v-model="configuration_path.CALPUFF.temperature" class="CALPUFF-input">
                                            <span slot="suffix">℃</span>
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12" :lg="7">
                                    <el-form-item label="烟气排放速度">
                                        <el-input v-model="configuration_path.CALPUFF.rate" class="CALPUFF-input">
                                            <span slot="suffix">Km/h</span>
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12" :lg="3" style="line-height: 32px">
                                    <!-- <el-form-item label="建筑物：" label-width="70px"> -->
                                    <el-checkbox v-model="configuration_path.CALPUFF.isBuilding">建筑物</el-checkbox>
                                    <!-- </el-form-item> -->
                                </el-col>
                            </el-row>
                        </el-form>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CALPUFF_CALMET_DAT文件位置">
                            <el-input v-model="configuration_path.CALPUFF_CALMET_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="PUFF_LST文件保存位置">
                            <el-input v-model="configuration_path.PUFF_LST" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CALPOST_DAT文件位置">
                            <el-input v-model="configuration_path.CALPOST_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="CALPOST_LST文件保存位置">
                            <el-input v-model="configuration_path.CALPOST_LST" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="PRTMET_DAT文件位置">
                            <el-input v-model="configuration_path.PRTMET_DAT" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" :xl="12">
                        <el-form-item label="PRTMET_LST文件保存位置">
                            <el-input v-model="configuration_path.PRTMET_LST" class="configuration-input"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" :xl="3">
                        <el-button type="primary" round icon="el-icon-brush" style="margin-bottom: 15px;width: 100%;">一键绘制</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </div>
</template>

<script>
import global_deterministic from '@/api/globalDeterm/setting.js'
import grapes_region_determ from '@/api/grapesRegionDeterm/setting.js'
import grapes_reps from '@/api/grapesReps/setting.js'
const mods = {global_deterministic, grapes_region_determ, grapes_reps}

export default {
    name: 'ModuleSetting',
    data() {
        // 置信度参数检验规则
        let checkConfidence = (rule, value, callback) => {
            if(value<0) return callback(new Error('置信度参数不能小于0'))
            else if(value>1) return callback(new Error('置信度参数不能大于1'))
            else callback()
        }
        return {
            // 整个页面的loading控制
            loading: true,
            // 对话框中的loading控制
            dialogLoading: true,
            // 服务器信息
            settingInfo: {
                server_info: [
                    {
                        server_name: '',    // 服务器名称
                        url: '',            // 服务器地址
                        name: '',           // 用户名
                        pwd: '',            // 密码
                        data_path: '',      // 数据存放路径
                        is_load: 1          // 是否缓存
                    },
                    {
                        server_name: '',    // 服务器名称
                        url: '',            // 服务器地址
                        name: '',           // 用户名
                        pwd: '',            // 密码
                        data_path: '',      // 数据存放路径
                        is_load: 0          // 是否缓存
                    }
                ],
                thresholds: null,     // 样本数阈值
                confidence_a: null,   // 置信度a
                confidence_b: null,   // 置信度b
                confidence_c: null,   // 置信度c
                position: null      // 用户权限
            },
            // 服务器连接测试前弹窗
            server_connect_info: false,
            // 连接前测试弹窗是否仅为提示信息
            server_connect_isInfo: false,
            // 服务器连接测试目标index
            server_connect_index: null,
            // 服务器表单校验规则
            serverformRules: {
                url: [{required: true, message: '请输入服务器地址', trigger: 'blur'}],
                name: [{required: true, message: '请输入用户名', trigger: 'blur'}],
                pwd: [{required: true, message: '请输入密码', trigger: 'blur'}],
                data_path: [{required: true, message: '请输入数据存放路径', trigger: 'blur'}],
                obs_data_path: [{required: true, message: '请输入数据存放路径', trigger: 'blur'}],
                fcst_data_path: [{required: true, message: '请输入数据存放路径', trigger: 'blur'}],
            },
            // 显著性检验表单校验规则
            significanceformRules: {
                confidence_a: [{required: true, validator: checkConfidence, trigger: 'blur'}],
                confidence_b: [{required: true, validator: checkConfidence, trigger: 'blur'}],
                confidence_c: [{required: true, validator: checkConfidence, trigger: 'blur'}],
            },
            // 缓存数据对话框
            cacheDialog: false,
            // 缓存数据表格加载动画
            cacheDialogLoading: false,
            // 缓存数据表格数据
            cacheData: [],
            // 项目成员管理对话框
            memberDialog: false,
            // 添加项目成员对话框
            addmemberDialog: false,
            // 项目成员数据
            memberData:[],
            // 搜索人员姓名
            searchMemberId: null,
            // 是否正在搜索
            searchLoading: false,
            // 搜索人员结果数据
            searchResult: [],
            // 运行日志对话框
            runlogDialog: false,
            // 运行日志表格数据
            runlogData: [],
            // 运行日志分页组件
            pagination: {
                currentPage: 1,
                pageCount: 1
            },
            // 大气扩散-坐标设置
            coordinate: {
                center: '',
                center_sign: '',
                first: '',
                first_sign: '',
                second: '',
                second_sign: '',
                Xdistance: '',
                Ydistance: '',
                startwidth: ''
            },
            // 大气扩散模块配置文件位置
            configuration_path: {
                TERRER_DAT: '',
                TERRER_LST: '',
                CTGPROC_DAT: '',
                CTGPROC_LST: '',
                GLAZAS: '',
                MAKEGEO_LU_DAT: '',
                MAKEGEO_TERR_DAT: '',
                GEO_DAT: '',
                GRAPES: '',
                GRAPES_23DDAT_OUTPUT: '',
                GRAPES_23DDAT: '',
                CALMET_GEO_DAT: '',
                CALMET_LST: '',
                CALMET_DAT: '',
                M3DDAT: '',
                CALPUFF: {
                    x: '',
                    y: '',
                    height: '',
                    temperature: '',
                    rate: '',
                    isBuilding: ''
                },
                CALPUFF_CALMET_DAT: '',
                PUFF_LST: '',
                CALPOST_DAT: '',
                CALPOST_LST: '',
                PRTMET_DAT: '',
                PRTMET_LST: ''
            }
        }
    },
    computed: {
        path(){
            return this.$route.path.split('/')[1];
        },
    },
    mounted(){
        const _this = this;
        _this.loading = true;
        _this.getModuleSetting();
    },
    methods: {
        // 设置页面加载获取数据
        getModuleSetting(){
            const _this = this;
            mods[_this.path].settingLoadInfo().then(res => {
                // 对返回数据预处理为前端格式
                res.data.server_info = [res.data.server_info]

                _this.settingInfo = res.data;

                // 默认业务模式缓存服务器数据
                _this.$set(_this.settingInfo['server_info'][0], 'is_load', 1)

                // 科研模式服务器每次加载都空上
                _this.settingInfo['server_info'].push({
                    server_name: 'ssh', // 服务器名称
                    url: '',            // 服务器地址
                    name: '',           // 用户名
                    pwd: '',            // 密码
                    obs_data_path: '',  // 数据存放路径
                    fcst_data_path: '', // 数据存放路径
                    is_load: 0          // 是否缓存
                })
                
                // 大气扩散模块
                // if(_this.path == "ADdashboard") _this.coordinate = res.data;
                _this.loading = false;
            })
            .catch(() => {
                _this.loading = false;
            });
        },
        // 切换服务器是否缓存
        change_server_load(index, new_value){
            let _this = this;
            mods[_this.path].changeServerLoad({type: index, is_load: new_value}).then(res => {
                if(res.data.status === 1) _this.$message.success('修改成功')
                else {
                    _this.$message.error('修改失败')
                    _this.settingInfo.server_info[index].is_load = new_value===0?1:0
                }
            })
        },
        // 服务器信息修改前确认弹窗
        serverConnectBefor(index, isInfo){
            this.server_connect_info = true
            this.server_connect_index = index
            this.server_connect_isInfo = isInfo
        },
        // 服务器信息修改后连接测试
        serverConnetTest(formName, index){
            console.log(formName, index);
            const _this = this;
            _this.$refs[formName][index].validate((valid) => {
                if (valid) {
                    // const {server_name, url, name, pwd, data_path} = _this.settingInfo.server_info[index];
                    mods[_this.path].updateServer({..._this.settingInfo.server_info[index], type: index, is_load: 0})
                    .then(res => {
                        if(res.data.status == 1){
                            _this.$message.success('连接成功，服务器信息修改成功');
                            _this.server_connect_info = false;
                        }
                        else{
                            _this.$message.error('连接失败，服务器不可用');
                        }
                    })
                } else {
                    _this.server_connect_info = false;
                    _this.$message.warning('服务器信息未填写完整');
                    return false;
                }
            });
            
        },
        // 样本数阈值修改
        changeThresholds(currentVal){
            const _this = this;
            if(this.path != 'grapes_reps'){
                mods[_this.path].updateThresholds({thresholds: currentVal})
                .then(res => {
                    res.data.status == 1 ? _this.$message.success('修改成功') : _this.$message.error('修改失败');
                })
            }else{
                mods[_this.path].changeMissingmembersThreshold({threshold: currentVal})
                .then(res => {
                    res.data.status == 1 ? _this.$message.success('修改成功') : _this.$message.error('修改失败');
                })
            }
        },
        // 置信度参数修改
        changeConfidence(level, confidence){
            const _this = this;

            _this.$refs['significanceForm'].validate((valid) => {
                if(valid){
                    // 输入合法性验证
                    const { confidence_a, confidence_b, confidence_c } = _this.settingInfo;
                    if(confidence_a > confidence_b && confidence_b > confidence_c){
                        mods[_this.path].updateConfidence({ level, confidence })
                        .then(res => {
                            res.data.status == 1 ? _this.$message.success('修改成功') : _this.$message.error('修改失败');
                        })
                    } else {
                        _this.$message.warning('置信度参数必须 a > b > c')
                        _this.$refs['significanceForm'].resetFields()
                    }
                }
                else return false
            })
        },

        // 获取缓存数据
        getCacheData(){
            this.dialogLoading = true
            this.cacheDialog = true;

            mods[this.path].loadBuffer()
            .then(({data}) => {
                let tabelData = []
                // 对得到数据进行预处理
                if(this.path == 'grapes_region_determ'){
                    for(let type_index in data.type){
                        // 得到数据类型（格点、站点）
                        let type = data.type[type_index] === 'an' ? '格点分析检验数据' : '站点观测检验数据'
                        let type_flag = false
                        let type_rowspan = 0

                        // 计算该类数据类型共有多少个日期
                        for(let mode in data.data[type_index]) {
                            if(data.data[type_index].hasOwnProperty(mode)){
                                type_rowspan += data.data[type_index][mode].length
                            }
                        }

                        // 添加日期表格数据
                        for(let mode in data.data[type_index]){
                            // 得到模式名称
                            let mode_flag = false
                            if(data.data[type_index].hasOwnProperty(mode)){
                                for(let date of data.data[type_index][mode]){
                                    // 若有模式名添加模式名与模式单元格占位行数
                                    if(!mode_flag) {
                                        // 若有类型名添加类型名与类型单元格占位行数
                                        if(!type_flag) {
                                            tabelData.push({type, mode, date, type_rowspan, mode_rowspan: data.data[type_index][mode].length})
                                            type_flag = true
                                        }
                                        else tabelData.push({mode, date, type_rowspan: 0, mode_rowspan: data.data[type_index][mode].length})
                                        mode_flag = true
                                    }else tabelData.push({type_rowspan: 0, mode_rowspan: 0, date})
                                }
                            }
                        }
                    }
                }
                else if(this.path == 'grapes_reps'){
                    for(let mode_index in data.data){
                        for(let date of data.data[mode_index].date){
                            tabelData.push({
                                mode: data.data[mode_index].mode,
                                element: data.data[mode_index].element,
                                date: date,
                                skillscores: data.data[mode_index].skillscores.join()
                            })
                        }
                    }
                }

                this.cacheData = tabelData
                this.dialogLoading = false
            })
        },
        // 缓存数据表格占位处理
        cacheSpanMethod({ row, column, rowIndex, columnIndex }){
            if(columnIndex === 0) {
                if(row.type_rowspan !== 0) return [row.type_rowspan, 1]
                else return [0, 0]
            }
            else if(columnIndex === 1){
                if(row.mode_rowspan !== 0) return [row.mode_rowspan, 1]
                else return [0, 0]
            }
        },
        // 清空缓存数据弹窗
        delcacheData(){
            this.$confirm('此操作将清空缓存数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                mods[this.path].clearBuffer().then(res => {
                    res.data.status == 1 ? this.$message.success('删除成功!') : this.$message.error('删除失败!')
                })
            })
        },
        // 获取当前项目成员数据
        getmemberData(){
            this.dialogLoading = true
            this.memberDialog = true
            this.memberData = []

            mods[this.path].loadMembers()
            .then(({data}) => {
                for(let index in data.name){
                    this.memberData.push({id: data.id[index], name: data.name[index], position: data.position[index]})
                }
                this.dialogLoading = false
            })
        },
        // 项目成员管理中，移除成员
        delmember(row){
            this.$confirm('此操作将该用户移除本项目, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                mods[this.path].delMember({id: row.id})
                .then(({data}) => {
                    if(data.status == 1){
                        this.$message.success('移除成功')
                        this.getmemberData()
                    }else this.$message.error('移除失败')
                })
            })
        },
        // 人员搜索
        searchMember(name){
            this.searchResult = []
            this.searchLoading = true
            if(name !== ''){
                mods[this.path].searchMember({name: name})
                .then(({data}) => {
                    if(data.is_selected == 1){
                        this.searchResult.push(data)
                        this.searchLoading = false
                    }else this.$message.warning("未找到用户")
                })
            }
        },
        // 添加项目人员
        addMember(id){
            mods[this.path].addMember({id: id})
            .then(({data}) => {
                if(data.status == 1){
                    this.$message.success('添加成功')
                    this.getmemberData()
                    this.addmemberDialog = false
                }else this.$message.error('添加失败')
            })
        },
        // 获取当前项目模块操作记录
        getorderData(page){
            this.dialogLoading = true
            this.runlogDialog = true
            this.runlogData = []

            mods[this.path].loadLog({page, pageSize: 10})
            .then(({data}) => {
                for(let index in data.info){
                    this.runlogData.push({
                        info: data.info[index],
                        marker: data.marker[index],
                        time: data.time[index]
                    })
                    this.pagination.pageCount = data.page_num
                }
                this.dialogLoading = false
            })
        },
    }
}
</script>

<style lang="scss" scoped>
    @import "@/assets/css/ADcontent.scss";
    @import "@/assets/css/formBox.scss";
</style>